package org.study.clickhouse.api.util;

import com.clickhouse.jdbc.ClickHouseDataSource;

import java.sql.*;
import java.util.Properties;

/**
 * 通过 HTTPS 协议连接 ClickHouse。
 * 参考 https://help.aliyun.com/document_detail/167430.html
 *
 * @author Administrator
 * @date 2022-03-16
 */
public class ClickHouseMainTest2 {
    public static void main(String[] args) throws SQLException {
        String url = "jdbc:clickhouse://127.0.0.1:8123/default?ssl=false";
        Properties props = new Properties();
        props.setProperty("user", "default");
        props.setProperty("password", "root");
        final ClickHouseDataSource dataSource = new ClickHouseDataSource(url, props);
        try (Connection conn = dataSource.getConnection();
             Statement statement = conn.createStatement();
             ResultSet resultSet = statement.executeQuery("select now()")) {
            if (resultSet.next()) {
                Timestamp now = resultSet.getTimestamp(1);
                System.out.println(now);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
